﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Display.GateUI {
    import flash.events.*;
    import flash.display.*;
    import flash.utils.*;
    import org.aswing.*;
    import Classes.*;
    import Classes.util.*;
    import org.aswing.geom.*;
    import Display.*;
    import flash.text.*;
    import org.aswing.border.*;
    import org.aswing.ext.*;
    import Display.aswingui.*;

    public class CrewGateDialog_2 extends GateDialog {

        protected static var crewScrollAssets:Dictionary = new Dictionary();

        protected var m_crew:CrewScrollingList;
        protected var m_dialogText:Component;
        protected var m_instructions:String;
        protected var m_numAssetLoads:int = 2;
        protected var m_imagesLoaded:int = 0;
        protected var m_comTabObject:Object;

        public function CrewGateDialog_2(_arg1:String, _arg2:Array, _arg3:GridListCellFactory, _arg4:String, _arg5:String, _arg6:Function, _arg7:Function, _arg8:int=3, _arg9:Number=395, _arg10:Boolean=true){
            this.m_instructions = _arg1;
            super(_arg2, _arg3, _arg4, _arg5, _arg6, _arg7, null, _arg8, 615, _arg9, _arg10);
        }
        public static function get assetDict():Dictionary{
            return (crewScrollAssets);
        }

        override protected function loadAssets():void{
            Global.delayedAssets.get(DelayedAssetLoader.GENERIC_DIALOG_ASSETS, makeAssets);
            Global.delayedAssets.get(DelayedAssetLoader.TABBED_ASSETS, this.makeTabAssets);
        }
        protected function makeTabAssets(_arg1:DisplayObject, _arg2:String):void{
            this.m_comTabObject = _arg1;
            this.onAssetsLoaded();
        }
        override protected function onAssetsLoaded(_arg1:Event=null):void{
            this.m_imagesLoaded++;
            if (this.m_imagesLoaded < this.m_numAssetLoads){
                return;
            };
            crewScrollAssets["dialog_bg"] = (new m_comObject.dialog_bg() as DisplayObject);
            crewScrollAssets["cell_bg"] = (new m_comObject.cell_bg() as DisplayObject);
            crewScrollAssets["cell_bg_alt"] = (new m_comObject.cell_bg_alt() as DisplayObject);
            crewScrollAssets["police_scrollContainer"] = this.m_comTabObject.police_scrollContainer;
            crewScrollAssets["conventionCenter_pagination_border"] = this.m_comTabObject.conventionCenter_pagination_border;
            crewScrollAssets["conventionCenter_pagination_bottom_disabled"] = this.m_comTabObject.conventionCenter_pagination_bottom_disabled;
            crewScrollAssets["conventionCenter_pagination_bottom_over"] = this.m_comTabObject.conventionCenter_pagination_bottom_over;
            crewScrollAssets["conventionCenter_pagination_bottom_up"] = this.m_comTabObject.conventionCenter_pagination_bottom_up;
            crewScrollAssets["conventionCenter_pagination_dot"] = this.m_comTabObject.conventionCenter_pagination_dot;
            crewScrollAssets["conventionCenter_pagination_top_disabled"] = this.m_comTabObject.conventionCenter_pagination_top_disabled;
            crewScrollAssets["conventionCenter_pagination_top_over"] = this.m_comTabObject.conventionCenter_pagination_top_over;
            crewScrollAssets["conventionCenter_pagination_top_up"] = this.m_comTabObject.conventionCenter_pagination_top_up;
            crewScrollAssets["slot_unfilled"] = this.m_comTabObject.police_slot_unfilled;
            this.createDialog();
        }
        override protected function onFinishClick(_arg1:Event):void{
            if (m_finishCheckCB()){
                countDialogAction("FINISH");
            } else {
                countDialogAction("ASK");
                this.inviteFriends(_arg1);
            };
            m_finishCB();
        }
        private function inviteFriends(_arg1:Event):void{
            dispatchEvent(new Event("friendClicked", true));
        }
        protected function onBuyClick(_arg1:Event):void{
            var _local4:Player;
            var _local2:int = this.nextHireIndex;
            if (_local2 == -1){
                return;
            };
            var _local3:Boolean = m_listData[this.nextHireIndex].buyCallback(this.nextHireCost);
            if (_local3){
                _local4 = Global.player.findFriendById("-1");
                m_listData[_local2].count++;
                m_listData[_local2].url = _local4.snUser.picture;
                m_listData[_local2].footerText = _local4.firstName;
                m_listData[_local2].picUrl = m_listData[_local2].url;
                m_listData[_local2].friendName = m_listData[_local2].footerText;
                this.m_crew.updateCell(_local2, m_listData[_local2]);
            };
            if (m_finishCheckCB()){
                this.activateFinishButton();
            };
        }
        protected function createDialogText():Component{
            var _local1:Container;
            var _local2:Component;
            if (this.m_instructions){
                _local1 = new JPanel(new FlowLayout(FlowLayout.CENTER));
                _local2 = ASwingHelper.makeMultilineText(this.m_instructions, 500, EmbeddedArt.DEFAULT_FONT_NAME_BOLD, TextFormatAlign.CENTER, 18, EmbeddedArt.brownTextColor);
                _local1.append(_local2);
            };
            return (_local1);
        }
        protected function get nextHireIndex():int{
            var _local1:int;
            while (_local1 < m_listData.length) {
                if (m_listData[_local1].count < m_listData[_local1].amountNeeded){
                    return (_local1);
                };
                _local1++;
            };
            return (-1);
        }
        protected function get nextHireCost():int{
            return (m_listData[this.nextHireIndex].cost);
        }
        override protected function createButtonPanel():Container{
            var _local2:EmptyBorder;
            var _local3:AssetIcon;
            var _local4:AssetIcon;
            var _local1:Container = new JPanel(new SoftBoxLayout(SoftBoxLayout.X_AXIS, 10, SoftBoxLayout.CENTER));
            if (m_finishCheckCB()){
                m_finishButton = new CustomButton(ZLoc.t("Dialogs", "FinishBuilding").toUpperCase(), null, "GreenButtonUI");
                m_finishButton.setEnabled(m_canBeFinished);
                m_finishButton.addActionListener(this.onFinishClick, 0, true);
                _local1.append(m_finishButton);
            } else {
                _local3 = new AssetIcon((new EmbeddedArt.icon_cash_big() as DisplayObject));
                m_finishButton = new CustomButton(ZLoc.t("Dialogs", "HireFriendsButtonLabel").toUpperCase(), null, "GreenButtonUI");
                m_finishButton.addActionListener(this.onFinishClick, 0, true);
                _local2 = new EmptyBorder(null, new Insets(0, 0, 0, 0));
                _local4 = new AssetIcon((new EmbeddedArt.icon_cash() as DisplayObject));
                m_buyAllButton = new CustomButton(ZLoc.t("Dialogs", "BuyCrewButtonLabel", {amount:String(this.nextHireCost)}).toUpperCase(), _local4, "CashButtonUI");
                m_buyAllButton.setMargin(new Insets(3, 10, 3, 10));
                m_buyAllButton.setFont(new ASFont(EmbeddedArt.TITLE_FONT, 20, false, false, false, EmbeddedArt.advancedFontProps));
                m_buyAllButton.addActionListener(this.onBuyClick, 0, true);
                _local1.append(m_finishButton);
                _local1.append(m_buyAllButton);
            };
            if (_local2){
                _local1.setBorder(_local2);
            };
            ASwingHelper.prepare(m_buttonPanel);
            return (_local1);
        }
        override protected function layoutComponents():void{
            var _local1:DisplayObject = (crewScrollAssets["dialog_bg"] as DisplayObject);
            var _local2:MarginBackground = new MarginBackground(_local1, new Insets(0, 0, 10, 0));
            m_jpanel.setBackgroundDecorator(_local2);
            m_jpanel.append(m_headerPanel);
            if (this.m_dialogText){
                m_jpanel.append(this.m_dialogText);
            };
            m_jpanel.append(m_listPanel);
            m_jpanel.append(m_buttonPanel);
            var _local3:IntDimension = new IntDimension(680, 515);
            m_jpanel.setMinimumSize(_local3);
            m_jpanel.setPreferredSize(_local3);
            m_jpanel.setMaximumSize(_local3);
            ASwingHelper.prepare(m_jpanel);
        }
        override protected function createListPanel():Component{
            var _local1:JPanel = ASwingHelper.makeSoftBoxJPanel(SoftBoxLayout.CENTER, 10);
            var _local2:JPanel = ASwingHelper.makeSoftBoxJPanelVertical(SoftBoxLayout.TOP);
            var _local3:IntDimension = new IntDimension(600, 370);
            _local2.setMinimumSize(_local3);
            _local2.setPreferredSize(_local3);
            _local2.setMaximumSize(_local3);
            this.m_crew = new CrewScrollingList(m_listData);
            ASwingHelper.prepare(this.m_crew);
            _local2.append(this.m_crew);
            ASwingHelper.prepare(_local2);
            _local1.appendAll(ASwingHelper.horizontalStrut(20), _local2);
            ASwingHelper.prepare(_local1);
            return (_local1);
        }
        override protected function createTitle():Component{
            var _local1:Number = TextFieldUtil.getLocaleFontSize(30, 23, null);
            var _local2:JTextField = ASwingHelper.makeTextField(m_title, EmbeddedArt.TITLE_FONT, _local1, EmbeddedArt.titleColor);
            _local2.filters = EmbeddedArt.titleFilters;
            var _local3:TextFormat = new TextFormat();
            _local3.size = (_local1 + 6);
            TextFieldUtil.formatSmallCaps(_local2.getTextField(), _local3);
            _local2.getTextField().height = 45;
            return (_local2);
        }
        override public function activateFinishButton():void{
            m_canBeFinished = true;
            m_buttonPanel.remove(m_finishButton);
            m_buttonPanel.remove(m_buyAllButton);
            m_buttonPanel = this.createButtonPanel();
            m_buttonPanel.append(m_finishButton);
            ASwingHelper.prepare(m_buttonPanel);
            this.layoutComponents();
        }
        override protected function createDialog():void{
            this.m_dialogText = this.createDialogText();
            super.createDialog();
        }

    }
}//package Display.GateUI 
